package com.itheima.tanhua.web;

import com.itheima.tanhua.service.ManagerService;
import com.itheima.tanhua.vo.PageResult;
import com.itheima.tanhua.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/manage")
public class ManagerController {

    @Autowired
    private ManagerService managerService;

    //用户数据翻页
    @GetMapping("/users")
    public ResponseEntity users(@RequestParam("id") Long userId, String nickname, @RequestParam(value = "page", defaultValue = "1") Integer page,
                                @RequestParam(value = "pagesize", defaultValue = "10") Integer pagesize, String city) {
        PageResult pageResult = managerService.findAll(userId, nickname, page, pagesize, city);
        return ResponseEntity.ok(pageResult);
    }
    //查看用户数据
    @GetMapping("/users/{userID}")
    public ResponseEntity findById(@PathVariable("userID")Long uid){
        UserInfoVo userInfoVo=managerService.findById(uid);
        return ResponseEntity.ok(userInfoVo);
    }

  //查看动态列表
  @GetMapping("/messages")
  public ResponseEntity messages(@RequestParam Map<String,String> map) {
        PageResult result = managerService.findAllMovements(map);
        return ResponseEntity.ok(result);
    }

    //用户冻结
    @PostMapping("/users/freeze")
    public ResponseEntity freeze(@RequestBody Map params) {
        Map map =  managerService.userFreeze(params);
        return ResponseEntity.ok(map);
    }

}
